﻿/****************************** Module Header ******************************\
 * Module Name:  JEditor.cs
 * Module Version:  2.0.0 (2012-10-18)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This componse is use for textarea.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UCF.Core.Web.CustomControls
{
    /// <summary>
    /// 可视化编辑器插件
    /// </summary>
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:Editor runat=server></{0}:Editor>")]
    public class JEditor : TextBox
    {
        protected override void OnPreRender(EventArgs e)
        {
            this.TextMode = TextBoxMode.MultiLine;
            Page.PreRenderComplete += PagePreRenderComplete;
            base.OnPreRender(e);
        }
        private void PagePreRenderComplete(object s, EventArgs e)
        {
            Page.ClientScript.RegisterClientScriptInclude("xheditor", "/DMS/Skin/Js/JqPlus/xHeditor/last/xheditor-last-zh-cn.min.js");
            Page.ClientScript.RegisterStartupScript(typeof(Page), this.UniqueID, string.Format("$('textarea[name=\"{0}\"]').xheditor({{upImgUrl:'{1}',upLinkUrl:'{1}',upFlashUrl:'{1}',upMediaUrl:'{1}'}});", this.UniqueID, "/DMS/Apis/p/FileUpload.ashx"), true);
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
            output.Write(Text);
        }
    }
}
